ValueFolderTemp='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsJournal\';
ValueFolderTemp2='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsEditor\';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
VecFigure=[{'Journal'} {'Year of first article recorded in PubMed'} {'N editors (% included in the analyses)'} {'N editor with only a PhD (%)'} {'Editors'' editorial experience (years, mean (SD))'} {'Editors'' experience in research (years, mean (SD))'} {'Editors'' postdoc experience (years, mean (SD))'}];
VecResultsTemp=zeros(3,33);
for n1=1:33
    VecResultsTemp2(n1,1)={[]};
end
VecResultsYear=NaN(1,33);
VecResultsTemp3=[];
VecResultsTemp4=[];
for n1=1:323
    if n1~=11
        ValueTemp=find(VecDistribution(:,1)==n1);
        ValueStartEditor=VecValueEditor{n1,22};
        ValueJournal=VecValueEditor{n1,11};
        n3=1;
        TestTemp=0;
        while n3<=size(VecValueJournal,1)&&TestTemp==0
            if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                TestTemp=1;
            else
                n3=n3+1;
            end
        end
        ValueTemp=VecValueEditor{n1,4};
        ValueTemp2=VecValueEditor{n1,6};
        ValueTemp3=VecValueEditor{n1,23};
        if size(ValueTemp,1)>0&&size(ValueTemp2,1)>0&&ischar(ValueTemp)==0&&ischar(ValueTemp2)==0&&isnan(ValueTemp)==0&&isnan(ValueTemp2)==0
            if ValueTemp2<ValueTemp
                n6=5;
            else
                n6=3;
            end
        else
            if size(ValueTemp,1)>0&&ischar(ValueTemp)==0&&isnan(ValueTemp)==0
                n6=3;
            else
                if size(ValueTemp2,1)>0&&ischar(ValueTemp2)==0&&isnan(ValueTemp2)==0
                    n6=5;
                else
                    n6=-1;
                end
            end
        end
        if size(ValueTemp3,1)>0&&ischar(ValueTemp3)==0&&isnan(ValueTemp3)==0
            n7=22;
        else
            n7=-1;
        end
        if n6>-1
            ValueDateTemp2=VecValueEditor{n1,n6};
            ValueTemp=find(ValueDateTemp2=='/');
            ValueMonthEditor=ValueDateTemp2(1,ValueTemp(1,1)+1:ValueTemp(1,2)-1);
            ValueYearEditor=ValueDateTemp2(1,ValueTemp(1,2)+1:end);
            ValueDateEditor=datenum(['01-' ValueMonthEditor '-' ValueYearEditor],'dd-mmm-yyyy');
            ValueDateReference=datenum('01-12-2020','dd-mmm-yyyy');
            Value15=(ValueDateReference-ValueDateEditor)/365.25;
        else
            Value15=NaN;
        end
        if n7>-1
            ValueDateTemp2=VecValueEditor{n1,n7};
            ValueTemp=find(ValueDateTemp2=='/');
            ValueMonthEditor=ValueDateTemp2(1,ValueTemp(1,1)+1:ValueTemp(1,2)-1);
            ValueYearEditor=ValueDateTemp2(1,ValueTemp(1,2)+1:end);
            ValueDateEditor=datenum(['01-' ValueMonthEditor '-' ValueYearEditor],'dd-mmm-yyyy');
            ValueDateReference=datenum('01-12-2020','dd-mmm-yyyy');
            Value16=(ValueDateReference-ValueDateEditor)/365.25;
        else
            if n6>-1
                Value16=Value15;
            else
                Value16=NaN;
            end
        end
        if n6>-1||n7>-1
            ValueTemp=VecValueEditor{n1,18};
            ValueTemp2=VecValueEditor{n1,19};
            ValueTemp3=VecValueEditor{n1,20};
            if ischar(ValueTemp3)==0&&ischar(ValueTemp2)==0
                ValueEditorTemp=VecValueEditor{n1,13};
                if strcmp(ValueEditorTemp,'Y')==0
                    Value11=ValueTemp3-ValueTemp2;
                else
                    Value11=NaN;
                end
            else
                Value11=NaN;
            end
            if ischar(ValueTemp3)==0&&ischar(ValueTemp)==0
                Value27=ValueTemp3-ValueTemp;
            else
                Value27=NaN;
            end
            if isnan(Value16)==0
%                 if Value16>=272/365.25
                    VecResultsYear(1,n3)=VecValueEditor{n1,12};
                    VecValueTemp2=VecResultsTemp2{n3,1};
                    VecValueTemp2=[VecValueTemp2;Value11 Value16 Value27];
                    VecResultsTemp2(n3,1)={VecValueTemp2};
                    VecResultsTemp3=[VecResultsTemp3;Value11 Value16 Value27 n3 1];
                    VecResultsTemp4=[VecResultsTemp4;Value11 Value16 Value27];
%                 end
            end
            VecResultsTemp(3,n3)=VecResultsTemp(3,n3)+1;
        end
        VecResultsTemp(1,n3)=VecResultsTemp(1,n3)+1;
        ValueEditorTemp=VecValueEditor{n1,13};
        if strcmp(ValueEditorTemp,'Y')==1
            VecResultsTemp(2,n3)=VecResultsTemp(2,n3)+1;
        end
    end
end
VecResultsTempNature=VecResultsTemp;
VecResultsTemp2Nature=VecResultsTemp2;

[VecEditorsTemp,VecEditorsTemp2,VecEditors1Temp]=xlsread('C:\Users\Remy Neveu\Desktop\Etude IRM\Article Region of interest\Etude Science.xlsx',2);
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
VecValueJournal(1:33,:)=[];
VecResultsTemp=zeros(3,6);
for n1=1:6
    VecResultsTemp2(n1,1)={[]};
end
VecResultsYear=NaN(1,6);
VecResultsTemp5=[];
for n1=1:45
    if n1~=11
        ValueTemp=find(VecDistribution(:,1)==n1);
        ValueStartEditor=VecValueEditor{n1,22};
        ValueJournal=VecValueEditor{n1,11};
        n3=1;
        TestTemp=0;
        while n3<=size(VecValueJournal,1)&&TestTemp==0
            if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                TestTemp=1;
            else
                n3=n3+1;
            end
        end
        ValueTemp=VecValueEditor{n1,4};
        ValueTemp2=VecValueEditor{n1,6};
        ValueTemp3=VecValueEditor{n1,23};
        if size(ValueTemp,1)>0&&size(ValueTemp2,1)>0&&ischar(ValueTemp)==0&&ischar(ValueTemp2)==0&&isnan(ValueTemp)==0&&isnan(ValueTemp2)==0
            if ValueTemp2<ValueTemp
                n6=5;
            else
                n6=3;
            end
        else
            if size(ValueTemp,1)>0&&ischar(ValueTemp)==0&&isnan(ValueTemp)==0
                n6=3;
            else
                if size(ValueTemp2,1)>0&&ischar(ValueTemp2)==0&&isnan(ValueTemp2)==0
                    n6=5;
                else
                    n6=-1;
                end
            end
        end
        if size(ValueTemp3,1)>0&&ischar(ValueTemp3)==0&&isnan(ValueTemp3)==0
            n7=22;
        else
            n7=-1;
        end
        if n6>-1
            ValueDateTemp2=VecValueEditor{n1,n6};
            ValueTemp=find(ValueDateTemp2=='/');
            ValueMonthEditor=ValueDateTemp2(1,ValueTemp(1,1)+1:ValueTemp(1,2)-1);
            ValueYearEditor=ValueDateTemp2(1,ValueTemp(1,2)+1:end);
            ValueDateEditor=datenum(['01-' ValueMonthEditor '-' ValueYearEditor],'dd-mmm-yyyy');
            ValueDateReference=datenum('01-12-2020','dd-mmm-yyyy');
            Value15=(ValueDateReference-ValueDateEditor)/365.25;
        else
            Value15=NaN;
        end
        if n7>-1
            ValueDateTemp2=VecValueEditor{n1,n7};
            ValueTemp=find(ValueDateTemp2=='/');
            ValueMonthEditor=ValueDateTemp2(1,ValueTemp(1,1)+1:ValueTemp(1,2)-1);
            ValueYearEditor=ValueDateTemp2(1,ValueTemp(1,2)+1:end);
            ValueDateEditor=datenum(['01-' ValueMonthEditor '-' ValueYearEditor],'dd-mmm-yyyy');
            ValueDateReference=datenum('01-12-2020','dd-mmm-yyyy');
            Value16=(ValueDateReference-ValueDateEditor)/365.25;
        else
            if n6>-1
                Value16=Value15;
            else
                Value16=NaN;
            end
        end
        if n6>-1||n7>-1
            ValueTemp=VecValueEditor{n1,18};
            ValueTemp2=VecValueEditor{n1,19};
            ValueTemp3=VecValueEditor{n1,20};
            if ischar(ValueTemp3)==0&&ischar(ValueTemp2)==0
                ValueEditorTemp=VecValueEditor{n1,13};
                if strcmp(ValueEditorTemp,'Y')==0
                    Value11=ValueTemp3-ValueTemp2;
                else
                    Value11=NaN;
                end
            else
                Value11=NaN;
            end
            if ischar(ValueTemp3)==0&&ischar(ValueTemp)==0
                Value27=ValueTemp3-ValueTemp;
            else
                Value27=NaN;
            end
            if isnan(Value16)==0
%                 if Value16>=272/365.25
                if Value16>=0
                    VecResultsYear(1,n3)=VecValueEditor{n1,12};
                    VecValueTemp2=VecResultsTemp2{n3,1};
                    VecValueTemp2=[VecValueTemp2;Value11 Value16 Value27];
                    VecResultsTemp3=[VecResultsTemp3;Value11 Value16 Value27 n3+33 2];
                    VecResultsTemp5=[VecResultsTemp5;Value11 Value16 Value27];
                    VecResultsTemp2(n3,1)={VecValueTemp2};
                end
%                 end
            end
            VecResultsTemp(3,n3)=VecResultsTemp(3,n3)+1;
        end
        if isnan(Value16)==0
            if Value16>=0
                VecResultsTemp(1,n3)=VecResultsTemp(1,n3)+1;
                ValueEditorTemp=VecValueEditor{n1,13};
                if strcmp(ValueEditorTemp,'Yes')==1
                    VecResultsTemp(2,n3)=VecResultsTemp(2,n3)+1;
                end
            end
        else
            VecResultsTemp(1,n3)=VecResultsTemp(1,n3)+1;
            ValueEditorTemp=VecValueEditor{n1,13};
            if strcmp(ValueEditorTemp,'Yes')==1
                VecResultsTemp(2,n3)=VecResultsTemp(2,n3)+1;
            end
        end
    end
end
VecResultsTempScience=VecResultsTemp;
VecResultsTemp2Science=VecResultsTemp2;

load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
VecResultsJournal=[];
VecResultsStartNature=[];
for n1=1:size(VecValueJournal,1)
    if n1<=33
        VecResultsTemp6=VecResultsTempNature;
        VecValueTemp=VecResultsTemp2Nature{n1,1};
        n1Temp=n1;
    else
        VecResultsTemp6=VecResultsTempScience;
        VecValueTemp=VecResultsTemp2Science{n1-33,1};
        n1Temp=n1-33;
    end
    if size(VecValueTemp,1)>1
        VecResultsJournalEditor=nanmean(VecValueTemp);
        VecResultsJournalEditorSD=sqrt(nanvar(VecValueTemp));
    else
        if size(VecValueTemp,1)==0
            VecResultsJournalEditor=-1*ones(1,3);
            VecResultsJournalEditorSD=zeros(1,3);
        else
            VecResultsJournalEditor=VecValueTemp;
            VecResultsJournalEditorSD=zeros(1,3);
        end
    end
    VecResultsTemp=[{VecValueJournal{n1,1}} {''} {num2str(VecResultsTemp6(1,n1Temp))} {[num2str(VecResultsTemp6(2,n1Temp)) ' (' num2str(VecResultsTemp6(2,n1Temp)/VecResultsTemp6(1,n1Temp)*100,3) ')']} {[num2str(VecResultsJournalEditor(1,2),3) ' (' num2str(VecResultsJournalEditorSD(1,2),3) ')']} {[num2str(VecResultsJournalEditor(1,3),3) ' (' num2str(VecResultsJournalEditorSD(1,3),3) ')']} {[num2str(VecResultsJournalEditor(1,1),3) ' (' num2str(VecResultsJournalEditorSD(1,1),3) ')']}];
%     VecResultsTemp=[{VecValueJournal{n1,1}} {''} {[num2str(VecResultsTemp6(1,n1Temp)) ' (' num2str(VecResultsTemp6(1,n1Temp)/VecResultsTemp6(3,n1Temp)*100,3) ')']} {[num2str(VecResultsTemp6(2,n1Temp)) ' (' num2str(VecResultsTemp6(2,n1Temp)/VecResultsTemp6(1,n1Temp)*100,3) ')']} {[num2str(VecResultsJournalEditor(1,2),3) ' (' num2str(VecResultsJournalEditorSD(1,2),3) ')']} {[num2str(VecResultsJournalEditor(1,3),3) ' (' num2str(VecResultsJournalEditorSD(1,3),3) ')']} {[num2str(VecResultsJournalEditor(1,1),3) ' (' num2str(VecResultsJournalEditorSD(1,1),3) ')']}];
    VecFigure=[VecFigure;VecResultsTemp];
end

VecValueTemp=VecResultsTemp2Nature{32,1};
VecValueTemp2=VecResultsTemp2Science{1,1};
VecResults=[];
for n1=1:size(VecValueTemp,2)
    ValueTemp=find(isnan(VecValueTemp(:,n1))==0);
    ValueTemp2=find(isnan(VecValueTemp2(:,n1))==0);
    [ValueResults,ValueResults2]=ttest2(VecValueTemp(ValueTemp,n1),VecValueTemp2(ValueTemp2,n1));
    ValueResults3=ranksum(VecValueTemp(ValueTemp,n1),VecValueTemp2(ValueTemp2,n1));
    VecResults=[VecResults;ValueResults2 ValueResults3];
end
ValueTemp=find(VecResultsTempScience(3,:)>0);
VecResultsTempScience2=VecResultsTempScience(:,ValueTemp);
[ValueResults,ValueResults2]=ttest2(VecResultsTempNature(2,:)./VecResultsTempNature(1,:),VecResultsTempScience2(2,:)./VecResultsTempScience2(1,:));
ValueResults3=ranksum(VecResultsTempNature(2,:)./VecResultsTempNature(1,:),VecResultsTempScience2(2,:)./VecResultsTempScience2(1,:));
VecResults=[VecResults;ValueResults2 ValueResults3];
[ValueResults,ValueResults2]=ttest2(VecResultsTempNature(2,1:31)./VecResultsTempNature(1,1:31),VecResultsTempScience2(2,2:end)./VecResultsTempScience2(1,2:end));
ValueResults3=ranksum(VecResultsTempNature(2,1:31)./VecResultsTempNature(1,1:31),VecResultsTempScience2(2,2:end)./VecResultsTempScience2(1,2:end));
VecResults=[VecResults;ValueResults2 ValueResults3];
[ValueResults,ValueResults2,stats]=fishertest([VecResultsTempNature(2,32) VecResultsTempScience2(2,1);VecResultsTempNature(1,32)-VecResultsTempNature(2,32) VecResultsTempScience2(1,1)-VecResultsTempScience2(2,1)]);
VecResults=[VecResults;ValueResults2 NaN];
for n1=1:size(VecResultsTemp4,2)
    [ValueResults,ValueResults2]=ttest2(VecResultsTemp4(:,n1),VecResultsTemp5(:,n1));
    ValueResults3=ranksum(VecResultsTemp4(:,n1),VecResultsTemp5(:,n1));
    VecResults=[VecResults;ValueResults2 ValueResults3];
end
VecResultsTemp6=[];
for n1=1:39
    ValueTemp=find(VecResultsTemp3(:,4)==n1);
    if size(ValueTemp,1)>=1
        if size(ValueTemp,1)>1
            VecResultsTemp6=[VecResultsTemp6;nanmean(VecResultsTemp3(ValueTemp,1:3)) VecResultsTemp3(ValueTemp(1,1),5)];
        else
            VecResultsTemp6=[VecResultsTemp6;VecResultsTemp3(ValueTemp,1:3) VecResultsTemp3(ValueTemp(1,1),5)];
        end
    end
end
for n1=1:3
    ValueTemp=find(VecResultsTemp6(:,end)==1&isnan(VecResultsTemp6(:,n1))==0);
    ValueTemp2=find(VecResultsTemp6(:,end)==2&isnan(VecResultsTemp6(:,n1))==0);
    [ValueResults,ValueResults2]=ttest2(VecResultsTemp6(ValueTemp,n1),VecResultsTemp6(ValueTemp2,n1));
    ValueResults3=ranksum(VecResultsTemp6(ValueTemp,n1),VecResultsTemp6(ValueTemp2,n1));
    VecResults=[VecResults;ValueResults2 ValueResults3];
end
    


% xlswrite('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\AnalyseScienceTable.xlsx',VecFigure);
% xlswrite('C:\Users\Remy Neveu\Desktop\Tests_R\AnalyseEtudeIRM\AnalyseMixedModelScienceTable.xlsx',VecResultsTemp3);
            